import Immutable from 'immutable';
import _ from 'lodash'

const defaultState = null;

export default function billLineReducer(state = defaultState, action) {
  switch(action.type) {
    case 'CREATE_BILL_LINE_DATA':
      var data = action.data;
      if (data.success) {
          return data.data;
      }else {
        return state;
      }
    case 'EDIT_BILL_LINE_DATA':
      var data = action.data
      var list = state;
      list.map(function(line) {
        if(line.id == data.id){
          line.description = data.description;
          line.taxable_amount = data.taxable_amount;
          line.tax = data.tax;
          line.gross_amount = data.gross_amount;
          line.expire_date = data.expire_date;
        }
      })
      return list;
    case 'DELETE_BILL_LINE_DATA':
      console.log(action.id);
      _.remove(state, function(line) {
        console.log(line.id, action.id)
        return action.id !== sysRole.id
      })
      return state;
    case 'ERROR_BILL_LINE':
      return action.error.status;
    case 'EMTPY_BILL_DATA':
      var data = null;
      return data;
    default:
      return null;
  }
}
